package world.liquor.dao;

import java.sql.SQLException;
import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Repository;

import world.liquor.domain.BeerInfo;

@Repository
public class BeerDAOImpl implements BeerDAO{
	
	@Autowired
	private SqlMapClientTemplate sqlMap;
	public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMap){
		this.sqlMap = sqlMap;	
	}
	
	
	//맥주등록
	public void insertBeer(BeerInfo beerInfo) throws SQLException{
		sqlMap.insert("insertBeer", beerInfo);
	}
	
	//맥주 업데이트: 아이디로 업데이트
	public int updateBeer(BeerInfo beerInfo) throws SQLException{
		return sqlMap.update("updateBeer", beerInfo);
	}
	
	//맥주삭제: 아이디로 삭제
	public int deleteBeerById(String beer_info_id) throws SQLException{
		return sqlMap.delete("deleteBeerById", beer_info_id);
	}
	
	//맥주 조회: 맥주아이디
	public BeerInfo selectBeerById(String beer_info_id) throws SQLException{
		return (BeerInfo)sqlMap.queryForObject("selectBeerById", beer_info_id);
	}
	
	//맥주 조회: 맥주이름
	public BeerInfo selectBeerByBeerName(String beer_info_name) throws SQLException{
		return (BeerInfo)sqlMap.queryForObject("selectBeerByBeerName", beer_info_name);
	}
	
	//맥주 조회: 제조사
	public ArrayList<BeerInfo> selectBeerByManufacturer(String manufacturer) throws SQLException{
		return (ArrayList<BeerInfo>)sqlMap.queryForList("selectBeerByManufacturer", manufacturer);
	}
	
	//맥주 조회: 나라
	public ArrayList<BeerInfo> selectBeerByCountry(String country) throws SQLException{
		return (ArrayList<BeerInfo>)sqlMap.queryForList("selectBeerByCountry", country);
	}
	
	//맥주 조회: 이름 or 제조사 or 나라
	public ArrayList<BeerInfo> selectBeerByMultipleCategory(String search_param) throws SQLException{
		return (ArrayList<BeerInfo>)sqlMap.queryForList("selectBeerByMultipleCategory", search_param);
	}
	
	//맥주 조회: 특정 회원이 평가한 맥주 정보 조회
	public ArrayList<BeerInfo> selectAssessedBeerInfo(String memberId) throws SQLException{
		return (ArrayList<BeerInfo>)sqlMap.queryForList("selectAssessedBeerInfo", memberId);
	}
	
	
	
	//맥주조회: 단맛>3
	public ArrayList<BeerInfo> selectBeerBySweetness() throws SQLException{
		return (ArrayList<BeerInfo>)sqlMap.queryForList("selectBeerBySweetness");
	}
	//맥주조회: 쓴맛>3
	public ArrayList<BeerInfo> selectBeerByBitterness() throws SQLException{
		return (ArrayList<BeerInfo>)sqlMap.queryForList("selectBeerByBitterness");
	}
	//맥주조회: 청량>3
	public ArrayList<BeerInfo> selectBeerByRefreshment() throws SQLException{
		return (ArrayList<BeerInfo>)sqlMap.queryForList("selectBeerByRefreshment");
	}
	//맥주조회: 색=5(흑맥주)
	public ArrayList<BeerInfo> selectBlackBeer() throws SQLException{
		return (ArrayList<BeerInfo>)sqlMap.queryForList("selectBlackBeer");
	}
	//맥주조회: 알콜도수>10
	public ArrayList<BeerInfo> selectLowAlcoholBeer() throws SQLException{
		return (ArrayList<BeerInfo>)sqlMap.queryForList("selectLowAlcoholBeer");
	}
	//맥주조회: 알콜도수<5
	public ArrayList<BeerInfo> selectHighAlcoholBeer() throws SQLException{
		return (ArrayList<BeerInfo>)sqlMap.queryForList("selectHighAlcoholBeer");
	}
	//맥주조회: 알콜도수=0
	public ArrayList<BeerInfo> selectNoAlcoholBeer() throws SQLException{
		return (ArrayList<BeerInfo>)sqlMap.queryForList("selectNoAlcoholBeer");
	}
	
	//모든 맥주 조회
	public ArrayList<BeerInfo> selectAllBeer() throws SQLException{
		return (ArrayList<BeerInfo>)sqlMap.queryForList("selectAllBeer");
	}

}
